package com.qili.aspect;

import com.qili.annotation.CheckMenuPermision;
import com.qili.service.base.BaseDictService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;

/**
 *@Auther liuyang
 *@Date 2020/12/8
 *@Version
 *@Desc     未生效,留作以后研究
 */
@Aspect
@Component
@SuppressWarnings({"unused"})
public class CheckMenuPermisionAspect {

    @Autowired
    private BaseDictService baseDictService;


    @Pointcut("@annotation(com.qili.annotation.CheckMenuPermision)")
    public void annotationPointcut() {

    }

    @Before("annotationPointcut()")
    public void beforePointcut(JoinPoint joinPoint){
        // 此处进入到方法前  可以实现一些业务逻辑
        //判断该用户是否有该菜单的权限,有的话,继续,没有的话抛出异常
        MethodSignature ms = (MethodSignature) joinPoint.getSignature();
        Method method = ms.getMethod();
        CheckMenuPermision annotation = method.getAnnotation(CheckMenuPermision.class);
//        String per = annotation.per();
//        boolean b = AuthUtil.checkHaveMenuAuth(per);
//        if(!b){
//            BaseDict baseDict = new BaseDict();
//            baseDict.setBadtCode(per);
//            baseDict.setBadtTypecode(DictTypes.QSQXTS.getType());
//            BaseDict baseDict1 = baseDictService.selectOne(baseDict);
////            throw new NoMenuPermisionException(baseDict1.getBadtName());
//        }
    }

}
